<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>新建工单</title>
    <link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
    <style type="text/css">
        .detail {
            padding-right: 20px!important;
        }

        h5 {
            color: #0062CC;
        }

        .mui-navigate-right .mui-col-xs-8 {
            width: 62.666667%!important;
        }

        .mui-text-right input,
        .mui-text-right textarea,
        textarea {
            border: 0;
            font-size: 14px;
            font-weight: 400;
            color: #8f8f94;
            margin-bottom: 0;
            text-align: right;
        }

        textarea {
            text-align: left;
        }
    </style>
</head>

<body>
    <div class="mui-content">
    	<ul class="mui-table-view mui-table-view-chevron type_list_spair">
            <li class="mui-table-view-cell detail">
                <div class="mui-table">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">工单编号：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="wonum"></span>
                    </div>
                </div>
            </li>
        </ul>
        <ul class="mui-table-view mui-table-view-chevron type_list_spair">
            <li class="mui-table-view-cell detail">
                <div class="mui-table">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">工单名称：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <input type="text" id="OrderName" placeholder="请输入工单名称" />
                    </div>
                </div>
            </li>
            <li class="mui-table-view-cell detail" onclick="openSaveWin('work_order_sel_workType','选择工单类型')">
                <div class="mui-table mui-navigate-right">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">工单类型：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="workType">请选择工单类型</span>
                    </div>
                </div>
            </li>
        </ul>
        <ul class="mui-table-view mui-table-view-chevron type_list_spair">
            <li class="mui-table-view-cell detail" onclick="openSaveWin('work_order_sel_address','选择位置')">
                <div class="mui-table mui-navigate-right">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">位置：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="LocationId">请选择位置</span>
                    </div>
                </div>
            </li>
            <li class="mui-table-view-cell detail">
                <div class="mui-table">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">位置描述：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="LocationName"></span>
                    </div>
                </div>
            </li>
        </ul>
        <ul class="mui-table-view mui-table-view-chevron type_list_spair">
            <li class="mui-table-view-cell detail" onclick="openSaveWin('work_order_sel_property','选择资产')">
                <div class="mui-table mui-navigate-right">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">资产：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="propertyId">请选择资产</span>
                    </div>
                </div>
            </li>
            <li class="mui-table-view-cell detail">
                <div class="mui-table">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">资产名称：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="propertyName"></span>
                    </div>
                </div>
            </li>
        </ul>
        <ul class="mui-table-view mui-table-view-chevron type_list_spair">
            <li class="mui-table-view-cell detail" onclick="openSaveWin('work_order_sel_fixArea','选择维修区域')">
                <div class="mui-table mui-navigate-right">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">维修区域：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="fixArea">请选择维修区域</span>
                    </div>
                </div>
            </li>
            <li class="mui-table-view-cell detail" onclick="openSaveWin('work_order_sel_manager','选择负责人',{lead: true})">
                <div class="mui-table mui-navigate-right">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">负责人：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="responseName">请选择负责人</span>
                    </div>
                </div>
            </li>
            <li class="mui-table-view-cell detail" onclick="openSaveWin('work_order_sel_manager','选择主管人',{manager: true})">
                <div class="mui-table mui-navigate-right">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">主管人：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="managerName">请选择主管人</span>
                    </div>
                </div>
            </li>
        </ul>
        <ul class="mui-table-view mui-table-view-chevron type_list_spair">
            <li class="mui-table-view-cell detail">
                <div class="mui-table">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">上传图片：</h5>
                    </div>
                </div>
                <div class="mui-table">
                    <ul class="mui-table-view mui-grid-view mui-grid-9 type_list_spair">
                        <li id="liAddPhoto" class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3" tapmode onclick="invokePictureTaker()"><img src="../image/upload.png" /></li>
                    </ul>
                </div>
            </li>
        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script src="../script/mui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../script/common.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    var OrderName = '',
        cRegion = '',
        assetnum = '',
        userID = '',
        leadID = '',
        workType = '',
        WorkPlace = '',
        wonum = '';
    var idList = []
    apiready = function() {
    	onLoadData();
    	cRegion = api.pageParam.locations;
    	$api.html($api.byId('LocationId'), api.pageParam.locations);
    	leadID = $api.getStorage('partsInfo').loginId;
        $api.html($api.byId('responseName'), $api.getStorage('partsInfo').userName);
        userID = $api.getStorage('partsInfo').loginId;
        $api.html($api.byId('managerName'), $api.getStorage('partsInfo').userName);
        api.addEventListener({
            name: 'LocactionId'
        }, function(resp, err) {
            cRegion = resp.value.locationName;
            WorkPlace = resp.value.c_region;
            $api.html($api.byId('LocationName'), resp.value.Location);
            $api.html($api.byId('LocationId'), resp.value.locationName);
            $api.html($api.byId('fixArea'), resp.value.c_region);
            ajaxrd("selectUserList", {
                cRegion: resp.value.c_region
            }, function(ret, err) {
              if (ret.list.length) {
                $api.html($api.byId('responseName'), ret.list[0].displayname)
                leadID = ret.list[0].loginid
              }
            })
            ajaxrd("selectAssetList", {
                location: resp.value.locationName
            }, function(ret, err) {
              if (ret.list.length) {
                assetnum = ret.list[0].assetnum
                $api.html($api.byId('propertyId'), ret.list[0].assetnum)
                $api.html($api.byId('propertyName'), ret.list[0].description)
              }
            })
        });
        api.addEventListener({
            name: 'PropertyId'
        }, function(ret, err) {
            assetnum = ret.value.propertyId;
            $api.html($api.byId('propertyId'), ret.value.propertyId)
            $api.html($api.byId('propertyName'), ret.value.description)
        });
        api.addEventListener({
            name: 'lead'
        }, function(ret, err) {
            leadID = ret.value.userID;
            $api.html($api.byId('responseName'), ret.value.userName)
        })
        api.addEventListener({
            name: 'ManagerCh'
        }, function(ret, err) {
            userID = ret.value.userID;
            $api.html($api.byId('managerName'), ret.value.userName)
        })
        api.addEventListener({
            name: 'workType'
        }, function(ret, err) {
            workType = ret.value.workType;
            $api.html($api.byId('workType'), ret.value.workType)
        })
        // 选择维修区域
        api.addEventListener({
           name: 'fixArea'
         }, function(ret, err) {
           WorkPlace = ret.value.fixAreaValue; $api.html($api.byId('fixArea'), ret.value.fixAreaValue)
        })
        api.addEventListener({
            name: 'navitembtn'
        }, function(ret, err) {
            if (ret.index == 0) {
                OrderName = $api.val($api.byId('OrderName'));
                if (OrderName == '') {
                    Toast('请输入工单名称！');
                    return
                }
                if (workType == '') {
                    Toast('请选择工单类型！');
                    return
                }
                if (cRegion == '') {
                    Toast('请选择位置！');
                    return
                }
                if (assetnum == '') {
                    Toast('请选择资产！');
                    return
                }
                if (WorkPlace == '') {
                    Toast('请选择维修区域！');
                    return
                }
                if (leadID == '') {
                    Toast('请选择负责人！');
                    return
                }
                if (userID == '') {
                    Toast('请选择主管人！');
                    return
                }
                ajaxrd("saveWorkOrder", {
                	workorderid: wonum,
                    description: OrderName,
                    worktype: workType,
                    location: cRegion,
                    assetnum: assetnum,
                    cRegion: WorkPlace,
                    lead: leadID,
                    supervisor: userID,
                    imgages: idList
                }, function(ret, err) {
                    api.sendEvent({
                        name: 'refersh',
                        extra: {
                            isrefersh: 'yes'
                        }
                    });
                    Toast('新增成功！');
                    setTimeout(function() {
                        api.closeWin();
                    }, 100)
                })
            } else { //扫码

            }
        });
    }
    //调用拍照功能
    function invokePictureTaker() {
        takePicture(function(localImgFile, id, id_sl) {
          //存储已拍照的照片
           idList.push({
             docinfoid: id,
             docinfoid_sl: id_sl,
           })
            //上传成功，则将照片加到列表中
            var liAddPhoto = $api.byId('liAddPhoto');
            $api.before(liAddPhoto, "<li class='mui-table-view-cell mui-media mui-col-xs-3' tapmode onclick=\"showLocalPicture('" + localImgFile + "')\">" +
                "<img class='mui-media-object' src='" + localImgFile + "'>" + "</li>");
            api.parseTapmode();
        });
    }
    function onLoadData () {
		ajaxrd("getWorkOrderNum", {
		}, function(ret, err) {
			wonum = ret.workorderid;
			$api.text($api.byId('wonum'),ret.workorderid)
		})
		if(api.pageParam.locations !== '')
		ajaxrd("selectLocationList", {
			locationName: api.pageParam.locations,
			pageNo: 1,
			pageSize: 10
		}, function(ret, err) {
			if(ret.list.length > 0){
			  WorkPlace = ret.list[0].c_region;
        $api.html($api.byId('fixArea'), ret.list[0].cRegion);
        $api.html($api.byId('LocationName'), ret.list[0].locationName);
        // 获取资产信息
        ajaxrd("selectAssetList", {
            location: ret.list[0].location
        }, function(ret, err) {
          if (ret.list.length) {
            $api.html($api.byId('propertyId'), ret.list[0].assetnum)
            $api.html($api.byId('propertyName'), ret.list[0].description)
          }
        })
     }
		})
	}
</script>

</html>
